package com.example.sunsg.okhttptest.customview;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;

import com.breadtrip.R;
import com.nineoldandroids.view.ViewHelper;

/**
 * Created on 2017/3/28 10:44
 *
 * @author zhangyanjiao
 * @desc 天气设置view 根据条件更新View
 */
public class WeatherViewGuide extends FrameLayout {
    private View mViewTop;
    private View mViewBottom;

    public WeatherViewGuide(Context context) {
        this(context, null);
    }

    public WeatherViewGuide(Context context, AttributeSet attrs) {
        this(context, attrs, -1);
    }

    public WeatherViewGuide(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context){
        inflate(context, R.layout.view_weather_lock_screen_guide,this);
    }

    private void setMinSize(){
        ViewHelper.setScaleX(this,0);
        ViewHelper.setScaleY(this,0);
    }

    public void startAnimation(){
        AnimatorSet sets = new AnimatorSet();

        AnimatorSet set1 = new AnimatorSet();

        ObjectAnimator objectAnimatorScaleX = ObjectAnimator.ofFloat(this,"scaleX",0f,1f);
        objectAnimatorScaleX.setRepeatCount(-1);

        ObjectAnimator objectAnimatorScaleY = ObjectAnimator.ofFloat(this,"scaleY",0f,1f);
        objectAnimatorScaleY.setRepeatCount(-1);

        ObjectAnimator objectAnimatorAlpherBootom1 = ObjectAnimator.ofFloat(mViewBottom,"alpha",1f,0.3f);
        objectAnimatorAlpherBootom1.setRepeatCount(-1);

        set1.setDuration(300);
        set1.playTogether(objectAnimatorScaleX,objectAnimatorScaleY,objectAnimatorAlpherBootom1);

        ObjectAnimator objectAnimatorAlpherBootom2 = ObjectAnimator.ofFloat(mViewBottom,"alpha",0.3f,0f);
        objectAnimatorAlpherBootom2.setDuration(200);
        objectAnimatorAlpherBootom2.setRepeatCount(-1);

        sets.playSequentially(set1,objectAnimatorAlpherBootom2);
        sets.start();
    }


    /**
     * 布局填充完毕
     */
    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mViewBottom = findViewById(R.id.view_bootom);
        mViewTop = findViewById(R.id.view_top);
//        startAnimation();
    }

}
